<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Hash;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class UserinfoController extends Controller
{
   
	public function getUserinfo()
	{
		
		return view('home/userinfo/userinfo');
	}

	//个人信息修改
	public function getUinfo(Request $request)
	{	

		//显示当前信息
		$usname = session('name');
		$info = DB::table('trip_user')->where('username',$usname)->first();
    	return view('home/userinfo/uinfo',['info'=>$info]);

	}

	public function postUpdate(Request $request)
	{
		$uname = session('name');
		//获取输入信息
		$data = $request->only('nickname','age','tell','email','sex','qq');
		//执行修改
		$res = DB::table('trip_user')->where('username',$uname)->update($data);
		//判断是否修改成功
    	if($res){
    		return redirect('/home/userinfo/uinfo')->with('success','用户修改成功');
    	}else{
    		return back()->with('error','用户修改失败');
    	}
	}

}
